import { getCity, setCity } from "./city";
import { API } from "./api";

const getCurrentCity = () => {
    const curCity = getCity();
    if (!curCity) {
        return new Promise(resolve => {
            const myCity = new window.BMap.LocalCity();
            myCity.get(async result => {
                const res = await API.get("/area/info", {
                    params: {
                        name: result.name
                    }
                })
                const { label, value } = res.data.body;
                setCity({
                    label,
                    value
                })
                //不要忘记，为了使用then方法,刻意包了一层promise
                resolve({ label, value })
            })
        })
    } else {
        return Promise.resolve(curCity)
    }
}
export { getCurrentCity, getCity, setCity }

// export { BASE_URL } from "./url"
// export { API } from "./api"
// export * from "./token"
